﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using HalconDotNet;

namespace DimensionalMeasurement
{
    public partial class FormBd : Form
    {
        #region 全局变量
        /// <summary>
        /// 相机图像
        /// </summary>
        HObject LeftUpImage, RightUpImage, LeftDownImage, RightDownImage;
        /// <summary>
        /// halcon窗体实例化对象
        /// </summary>
        HWindow[] hwindow = new HWindow[4];
        /// <summary>
        /// 图像找边类实例化对象
        /// </summary>
        ImageProcesses imageprocesses = new ImageProcesses();
        /// <summary>
        /// 左上相机图像坐标
        /// </summary>
        double[] LeftUpRowCross = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
        double[] LeftUpColCross = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
        /// <summary>
        /// 右上相机图像坐标
        /// </summary>
        double[] RightUpRowCross = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
        double[] RightUpColCross = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
        /// <summary>
        /// 左下相机图像坐标
        /// </summary>
        double[] LeftDownRowCross = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
        double[] LeftDownColCross = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
        /// <summary>
        /// 右下相机图像坐标
        /// </summary>
        double[] RightDownRowCross = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
        double[] RightDownColCross = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
        /// <summary>
        /// 边缘提取方式,'negative'从白到黑,'positive'从黑到白,'all'都可以
        /// </summary>
        private string hv_Transition = "all";
        /// <summary>
        /// 选择点
        /// </summary>
        private string hv_Select;
        private int hv_Step = 5;
        /// <summary>
        /// 阈值（黑白灰度差）
        /// </summary>
        private int hv_Gray = 25;
        /// <summary>
        /// 正负极
        /// </summary>
        string NOrP;
        #endregion

        public FormBd(HObject[] image, string NOrP)
        {

            InitializeComponent();

            for (int i = 0; i < hwindow.Length; i++)
            {
                hwindow[i] = new HWindow();
            }
            this.NOrP = NOrP;
            if (PublicSet.Myset.DetectMode == "3相机正负单测")
            {
                LeftUpImage = image[0];
                RightUpImage = image[1];
                LeftDownImage = image[2];
                return;
            }
            if (PublicSet.Myset.DetectMode == "2相机正负双测" && NOrP == "N")
            {
                LeftUpImage = image[0]; LeftDownImage = image[1];
                return;
            }
            if (PublicSet.Myset.DetectMode == "2相机正负双测" && NOrP == "P")
            {
                RightUpImage = image[0]; RightDownImage = image[1];
                return;
            }
            LeftUpImage = image[0];
            RightUpImage = image[1];
            LeftDownImage = image[2];
            RightDownImage = image[3];
        }

        private void FormBd_Load(object sender, EventArgs e)
        {
            hwindow[0].OpenWindow(0, 0, pLeftUp.Width, pLeftUp.Height, pLeftUp.Handle, "visible", "");
            hwindow[1].OpenWindow(0, 0, pRightUp.Width, pRightUp.Height, pRightUp.Handle, "visible", "");
            hwindow[2].OpenWindow(0, 0, pLeftDown.Width, pLeftDown.Height, pLeftDown.Handle, "visible", "");
            hwindow[3].OpenWindow(0, 0, pRightDown.Width, pRightDown.Height, pRightDown.Handle, "visible", "");


            pLeftUp.MouseWheel += PLeftUpHMouseWheel;
            pRightUp.MouseWheel += PRightUpHMouseWheel;
            pLeftDown.MouseWheel += PLeftDownHMouseWheel;
            pRightDown.MouseWheel += PRightDownHMouseWheel;


            if (PublicSet.Myset.DetectMode == "3相机正负单测")
            {
                if (LeftUpImage != null && RightUpImage != null && LeftDownImage != null)
                {
                    HOperatorSet.GetImageSize(LeftUpImage, out HTuple LeftUpWidth, out HTuple LeftUpHeight);
                    HOperatorSet.GetImageSize(RightUpImage, out HTuple RightUpWidth, out HTuple RightUpHeight);
                    HOperatorSet.GetImageSize(LeftDownImage, out HTuple LeftDownWidth, out HTuple LeftDownHeight);
                    //   HOperatorSet.GetImageSize(RightDownImage, out HTuple RightDownWidth, out HTuple RightDownHeight);
                    hwindow[0].SetPart(0, 0, LeftUpHeight.D, LeftUpWidth.D);
                    hwindow[1].SetPart(0, 0, RightUpHeight.D, RightUpWidth.D);
                    hwindow[2].SetPart(0, 0, LeftDownHeight.D, LeftDownWidth.D);
                    //  hwindow[3].SetPart(0, 0, RightDownHeight.D, RightDownWidth.D);
                    hwindow[0].DispObj(LeftUpImage);
                    hwindow[1].DispObj(RightUpImage);
                    hwindow[2].DispObj(LeftDownImage);
                    //  hwindow[3].DispObj(RightDownImage);
                    return;
                }

            }
            if (PublicSet.Myset.DetectMode == "2相机正负双测")
            {
                if (LeftUpImage != null && LeftDownImage != null && NOrP == "N")
                {
                    HOperatorSet.GetImageSize(LeftUpImage, out HTuple LeftUpWidth, out HTuple LeftUpHeight);
                    HOperatorSet.GetImageSize(LeftDownImage, out HTuple LeftDownWidth, out HTuple LeftDownHeight);
                    hwindow[0].SetPart(0, 0, LeftUpHeight.D, LeftUpWidth.D);
                    hwindow[2].SetPart(0, 0, LeftDownHeight.D, LeftDownWidth.D);
                    hwindow[0].DispObj(LeftUpImage);
                    hwindow[2].DispObj(LeftDownImage);
                }
                else
                {
                    if (RightUpImage != null && RightDownImage != null)
                    {
                        HOperatorSet.GetImageSize(RightUpImage, out HTuple RightUpWidth, out HTuple RightUpHeight);
                        HOperatorSet.GetImageSize(RightDownImage, out HTuple RightDownWidth, out HTuple RightDownHeight);
                        hwindow[1].SetPart(0, 0, RightUpHeight.D, RightUpWidth.D);
                        hwindow[3].SetPart(0, 0, RightDownHeight.D, RightDownWidth.D);
                        hwindow[1].DispObj(RightUpImage);
                        hwindow[3].DispObj(RightDownImage);
                    }
                }
            }



            if (LeftUpImage != null && RightUpImage != null && LeftDownImage != null && RightDownImage != null)
            {
                HOperatorSet.GetImageSize(LeftUpImage, out HTuple LeftUpWidth, out HTuple LeftUpHeight);
                HOperatorSet.GetImageSize(RightUpImage, out HTuple RightUpWidth, out HTuple RightUpHeight);
                HOperatorSet.GetImageSize(LeftDownImage, out HTuple LeftDownWidth, out HTuple LeftDownHeight);
                HOperatorSet.GetImageSize(RightDownImage, out HTuple RightDownWidth, out HTuple RightDownHeight);
                hwindow[0].SetPart(0, 0, LeftUpHeight.D, LeftUpWidth.D);
                hwindow[1].SetPart(0, 0, RightUpHeight.D, RightUpWidth.D);
                hwindow[2].SetPart(0, 0, LeftDownHeight.D, LeftDownWidth.D);
                hwindow[3].SetPart(0, 0, RightDownHeight.D, RightDownWidth.D);
                hwindow[0].DispObj(LeftUpImage);
                hwindow[1].DispObj(RightUpImage);
                hwindow[2].DispObj(LeftDownImage);
                hwindow[3].DispObj(RightDownImage);
            }
        }

        private void bClose_Click(object sender, EventArgs e)
        {
            // System.Environment.Exit(0);        
            Close();
        }

        #region 左上相机     
        private void PLeftUpHMouseWheel(object sender, MouseEventArgs e)
        {
            if (LeftUpImage != null && LeftUpImage.IsInitialized())
            {
                Tool.HMouseWheel(e, hwindow[0], LeftUpImage);
                for (int i = 0; i < 8; ++i)
                {
                    HOperatorSet.DispCross(hwindow[0], LeftUpRowCross[i], LeftUpColCross[i], 30, 0);
                }
            }
        }
        private void pLeftUp_MouseMove(object sender, MouseEventArgs e)
        {

        }

        private void pLeftUp_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                //if (LeftUpImage != null && LeftUpImage.IsInitialized())
                //{
                //    try
                //    {
                //        hwindow[0].GetMposition(out int row, out int column, out _);
                //        Tool.RowDown = row;    //鼠标按下时的行坐标
                //        Tool.ColDown = column; //鼠标按下时的列坐标
                //        Tool.IsEventArgs = true;//记录鼠标按下
                //    }
                //    catch (Exception)
                //    {
                //    }
                //}
                if (e.Clicks == 2)
                {
                    if (LeftUpImage != null && LeftUpImage.IsInitialized())
                    {
                        HOperatorSet.GetImageSize(LeftUpImage, out HTuple width, out HTuple height);
                        HOperatorSet.SetPart(hwindow[0], 0, 0, height.I, width.I);
                        HOperatorSet.DispObj(LeftUpImage, hwindow[0]);
                        for (int i = 0; i < 8; ++i)
                        {
                            HOperatorSet.DispCross(hwindow[0], LeftUpRowCross[i], LeftUpColCross[i], 30, 0);
                        }
                    }
                }
            }
        }

        private void pLeftUp_MouseUp(object sender, MouseEventArgs e)
        {
            Tool.IsEventArgs = false;//记录鼠标抬起后，移动图像
        }
        private void bLeftUp1_Click(object sender, EventArgs e)
        {
            pLeftUp.MouseWheel -= PLeftUpHMouseWheel;
            GetParam();
            List<double> RList = GetInterPoint1(LeftUpImage, hwindow[0], LeftUpRowCross, LeftUpColCross);
            if (RList.Count == 2)
            {
                tbLeftUpRow1.Text = RList[0].ToString();
                tbLeftUpCol1.Text = RList[1].ToString();
                LeftUpRowCross[0] = RList[0];
                LeftUpColCross[0] = RList[1];
            }
            pLeftUp.MouseWheel += PLeftUpHMouseWheel;
        }

        private void bLeftUp2_Click(object sender, EventArgs e)
        {
            pLeftUp.MouseWheel -= PLeftUpHMouseWheel;
            GetParam();
            List<double> RList = GetInterPoint1(LeftUpImage, hwindow[0], LeftUpRowCross, LeftUpColCross);

            if (RList.Count == 2)
            {
                tbLeftUpRow2.Text = RList[0].ToString();
                tbLeftUpCol2.Text = RList[1].ToString();
                LeftUpRowCross[1] = RList[0];
                LeftUpColCross[1] = RList[1];
            }
            pLeftUp.MouseWheel += PLeftUpHMouseWheel;
        }

        private void bLeftUp3_Click(object sender, EventArgs e)
        {
            pLeftUp.MouseWheel -= PLeftUpHMouseWheel;
            GetParam();
            List<double> RList = GetInterPoint1(LeftUpImage, hwindow[0], LeftUpRowCross, LeftUpColCross);

            if (RList.Count == 2)
            {
                tbLeftUpRow3.Text = RList[0].ToString();
                tbLeftUpCol3.Text = RList[1].ToString();
                LeftUpRowCross[2] = RList[0];
                LeftUpColCross[2] = RList[1];
            }
            pLeftUp.MouseWheel += PLeftUpHMouseWheel;
        }
        private void bLeftUp4_Click(object sender, EventArgs e)
        {
            pLeftUp.MouseWheel -= PLeftUpHMouseWheel;
            GetParam();
            List<double> RList = GetInterPoint1(LeftUpImage, hwindow[0], LeftUpRowCross, LeftUpColCross);

            if (RList.Count == 2)
            {
                tbLeftUpRow4.Text = RList[0].ToString();
                tbLeftUpCol4.Text = RList[1].ToString();
                LeftUpRowCross[3] = RList[0];
                LeftUpColCross[3] = RList[1];
            }
            pLeftUp.MouseWheel += PLeftUpHMouseWheel;
        }
        private void bLeftUp5_Click(object sender, EventArgs e)
        {
            pLeftUp.MouseWheel -= PLeftUpHMouseWheel;
            GetParam();
            List<double> RList = GetInterPoint1(LeftUpImage, hwindow[0], LeftUpRowCross, LeftUpColCross);
            if (RList.Count == 2)
            {
                tbLeftUpRow5.Text = RList[0].ToString();
                tbLeftUpCol5.Text = RList[1].ToString();
                LeftUpRowCross[4] = RList[0];
                LeftUpColCross[4] = RList[1];
            }
            pLeftUp.MouseWheel += PLeftUpHMouseWheel;
        }
        private void bLeftUp6_Click(object sender, EventArgs e)
        {
            pLeftUp.MouseWheel -= PLeftUpHMouseWheel;
            GetParam();
            List<double> RList = GetInterPoint1(LeftUpImage, hwindow[0], LeftUpRowCross, LeftUpColCross);
            if (RList.Count == 2)
            {
                tbLeftUpRow6.Text = RList[0].ToString();
                tbLeftUpCol6.Text = RList[1].ToString();
                LeftUpRowCross[5] = RList[0];
                LeftUpColCross[5] = RList[1];
            }
            pLeftUp.MouseWheel += PLeftUpHMouseWheel;
        }

        private void bLeftUp7_Click(object sender, EventArgs e)
        {
            pLeftUp.MouseWheel -= PLeftUpHMouseWheel;
            GetParam();
            List<double> RList = GetInterPoint1(LeftUpImage, hwindow[0], LeftUpRowCross, LeftUpColCross);
            if (RList.Count == 2)
            {
                tbLeftUpRow7.Text = RList[0].ToString();
                tbLeftUpCol7.Text = RList[1].ToString();
                LeftUpRowCross[6] = RList[0];
                LeftUpColCross[6] = RList[1];
            }
            pLeftUp.MouseWheel += PLeftUpHMouseWheel;
        }

        private void bLeftUp8_Click(object sender, EventArgs e)
        {
            pLeftUp.MouseWheel -= PLeftUpHMouseWheel;
            GetParam();
            List<double> RList = GetInterPoint1(LeftUpImage, hwindow[0], LeftUpRowCross, LeftUpColCross);
            if (RList.Count == 2)
            {
                tbLeftUpRow8.Text = RList[0].ToString();
                tbLeftUpCol8.Text = RList[1].ToString();
                LeftUpRowCross[7] = RList[0];
                LeftUpColCross[7] = RList[1];
            }
            pLeftUp.MouseWheel += PLeftUpHMouseWheel;
        }
        private void bLeftUp9_Click(object sender, EventArgs e)
        {
            pLeftUp.MouseWheel -= PLeftUpHMouseWheel;
            GetParam();
            List<double> RList = GetInterPoint1(LeftUpImage, hwindow[0], LeftUpRowCross, LeftUpColCross);
            if (RList.Count == 2)
            {
                tbLeftUpRow9.Text = RList[0].ToString();
                tbLeftUpCol9.Text = RList[1].ToString();
                LeftUpRowCross[8] = RList[0];
                LeftUpColCross[8] = RList[1];
            }
            pLeftUp.MouseWheel += PLeftUpHMouseWheel;
        }

        private void button5_Click(object sender, EventArgs e)
        {
            //左上相机
            double[] Row = new double[9]; double[] Col = new double[9];
            double[] RowPhy = new double[9]; double[] ColPhy = new double[9];

            //图像坐标
            Row[0] = double.Parse(tbLeftUpRow1.Text);
            Row[1] = double.Parse(tbLeftUpRow2.Text);
            Row[2] = double.Parse(tbLeftUpRow3.Text);
            Row[3] = double.Parse(tbLeftUpRow4.Text);
            Row[4] = double.Parse(tbLeftUpRow5.Text);
            Row[5] = double.Parse(tbLeftUpRow6.Text);
            Row[6] = double.Parse(tbLeftUpRow7.Text);
            Row[7] = double.Parse(tbLeftUpRow8.Text);
            Row[8] = double.Parse(tbLeftUpRow9.Text);
            Col[0] = double.Parse(tbLeftUpCol1.Text);
            Col[1] = double.Parse(tbLeftUpCol2.Text);
            Col[2] = double.Parse(tbLeftUpCol3.Text);
            Col[3] = double.Parse(tbLeftUpCol4.Text);
            Col[4] = double.Parse(tbLeftUpCol5.Text);
            Col[5] = double.Parse(tbLeftUpCol6.Text);
            Col[6] = double.Parse(tbLeftUpCol7.Text);
            Col[7] = double.Parse(tbLeftUpCol8.Text);
            Col[8] = double.Parse(tbLeftUpCol9.Text);
            //世界坐标
            RowPhy[0] = double.Parse(tbLeftUpY1.Text);
            RowPhy[1] = double.Parse(tbLeftUpY2.Text);
            RowPhy[2] = double.Parse(tbLeftUpY3.Text);
            RowPhy[3] = double.Parse(tbLeftUpY4.Text);
            RowPhy[4] = double.Parse(tbLeftUpY5.Text);
            RowPhy[5] = double.Parse(tbLeftUpY6.Text);
            RowPhy[6] = double.Parse(tbLeftUpY7.Text);
            RowPhy[7] = double.Parse(tbLeftUpY8.Text);
            RowPhy[8] = double.Parse(tbLeftUpY9.Text);

            ColPhy[0] = double.Parse(tbLeftUpX1.Text);
            ColPhy[1] = double.Parse(tbLeftUpX2.Text);
            ColPhy[2] = double.Parse(tbLeftUpX3.Text);
            ColPhy[3] = double.Parse(tbLeftUpX4.Text);
            ColPhy[4] = double.Parse(tbLeftUpX5.Text);
            ColPhy[5] = double.Parse(tbLeftUpX6.Text);
            ColPhy[6] = double.Parse(tbLeftUpX7.Text);
            ColPhy[7] = double.Parse(tbLeftUpX8.Text);
            ColPhy[8] = double.Parse(tbLeftUpX9.Text);


            if (PublicSet.Myset.DetectMode == "3相机正负单测" && NOrP == "N")
            {
                string path = PublicSet.path + "\\矩阵文件\\1负极左上相机.tup";
                //生成转换矩阵
                HOperatorSet.VectorToHomMat2d(Row, Col, RowPhy, ColPhy, out PublicSet.NLeftUpHomMat2D);
                //保存矩阵
                HOperatorSet.WriteTuple(PublicSet.NLeftUpHomMat2D, path); return;
            }
            else if (PublicSet.Myset.DetectMode == "3相机正负单测")
            {
                string path = PublicSet.path + "\\矩阵文件\\1正极左上相机.tup";
                //生成转换矩阵
                HOperatorSet.VectorToHomMat2d(Row, Col, RowPhy, ColPhy, out PublicSet.PLeftUpHomMat2D);
                //保存矩阵
                HOperatorSet.WriteTuple(PublicSet.PLeftUpHomMat2D, path); return;
            }

            if (NOrP == "N")
            {
                string path = PublicSet.path + "\\矩阵文件\\1负极左上相机.tup";
                //生成转换矩阵
                HOperatorSet.VectorToHomMat2d(Row, Col, RowPhy, ColPhy, out PublicSet.NLeftUpHomMat2D);
                //保存矩阵
                HOperatorSet.WriteTuple(PublicSet.NLeftUpHomMat2D, path);
            }
            else
            {
                string path = PublicSet.path + "\\矩阵文件\\5正极左上相机.tup";
                //生成转换矩阵
                HOperatorSet.VectorToHomMat2d(Row, Col, RowPhy, ColPhy, out PublicSet.PLeftUpHomMat2D);
                //保存矩阵
                HOperatorSet.WriteTuple(PublicSet.PLeftUpHomMat2D, path);

            }
            ToastNotification.Show("成功");
        }
        private void button6_Click(object sender, EventArgs e)
        {
            //验证左上矩阵
            GetParam();
            List<double> RList = GetInterPoint1(LeftUpImage, hwindow[0], LeftUpRowCross, LeftUpColCross);
            if (RList.Count == 2)
            {
                HOperatorSet.AffineTransPoint2d((NOrP == "N" ? PublicSet.NLeftUpHomMat2D : PublicSet.PLeftUpHomMat2D), RList[0], RList[1], out HTuple PhyY, out HTuple PhyX);
                hwindow[0].NewLine();
                HOperatorSet.WriteString(hwindow[0], "物理坐标X:" + PhyX.D.ToString("0.000") + "Y:" + PhyY.D.ToString("0.000"));
            }
            else
            {
                ToastNotification.Show("未得到横竖线交点，无法验证！");
            }
        }


        #endregion

        #region 右上相机

        private void PRightUpHMouseWheel(object sender, MouseEventArgs e)
        {
            if (RightUpImage != null && RightUpImage.IsInitialized())
            {
                Tool.HMouseWheel(e, hwindow[1], RightUpImage);
                for (int i = 0; i < 8; ++i)
                {
                    HOperatorSet.DispCross(hwindow[1], RightUpRowCross[i], RightUpColCross[i], 30, 0);
                }
            }
        }



        private void pRightUp_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                if (RightUpImage != null && RightUpImage.IsInitialized())
                {
                    //try
                    //{
                    //    hwindow[1].GetMposition(out int row, out int column, out _);
                    //    Tool.RowDown = row;    //鼠标按下时的行坐标
                    //    Tool.ColDown = column; //鼠标按下时的列坐标
                    //    Tool.IsEventArgs = true;//记录鼠标按下
                    //}
                    //catch (Exception)
                    //{
                    //}
                }
                if (e.Clicks == 2)
                {
                    if (RightUpImage != null && RightUpImage.IsInitialized())
                    {
                        HOperatorSet.GetImageSize(RightUpImage, out HTuple width, out HTuple height);
                        HOperatorSet.SetPart(hwindow[1], 0, 0, height.I, width.I);
                        HOperatorSet.DispObj(RightUpImage, hwindow[1]);
                        for (int i = 0; i < 8; ++i)
                        {
                            HOperatorSet.DispCross(hwindow[1], RightUpRowCross[i], RightUpColCross[i], 30, 0);
                        }
                    }
                }
            }
        }

        private void pRightUp_MouseUp(object sender, MouseEventArgs e)
        {
            Tool.IsEventArgs = false;//记录鼠标抬起后，移动图像
        }


        private void bRightUp1_Click(object sender, EventArgs e)
        {
            pRightUp.MouseWheel -= PRightUpHMouseWheel;
            GetParam();
            List<double> RList = GetInterPoint1(RightUpImage, hwindow[1], RightUpRowCross, RightUpColCross);

            if (RList.Count == 2)
            {
                tbRightUpRow1.Text = RList[0].ToString();
                tbRightUpCol1.Text = RList[1].ToString();
                RightUpRowCross[0] = RList[0];
                RightUpColCross[0] = RList[1];
            }
            pRightUp.MouseWheel += PRightUpHMouseWheel;
        }

        private void bRightUp2_Click(object sender, EventArgs e)
        {
            pRightUp.MouseWheel -= PRightUpHMouseWheel;
            GetParam();
            List<double> RList = GetInterPoint1(RightUpImage, hwindow[1], RightUpRowCross, RightUpColCross);

            if (RList.Count == 2)
            {
                tbRightUpRow2.Text = RList[0].ToString();
                tbRightUpCol2.Text = RList[1].ToString();
                RightUpRowCross[1] = RList[0];
                RightUpColCross[1] = RList[1];
            }
            pRightUp.MouseWheel += PRightUpHMouseWheel;
        }

        private void bRightUp3_Click(object sender, EventArgs e)
        {
            pRightUp.MouseWheel -= PRightUpHMouseWheel;
            GetParam();
            List<double> RList = GetInterPoint1(RightUpImage, hwindow[1], RightUpRowCross, RightUpColCross);

            if (RList.Count == 2)
            {
                tbRightUpRow3.Text = RList[0].ToString();
                tbRightUpCol3.Text = RList[1].ToString();
                RightUpRowCross[2] = RList[0];
                RightUpColCross[2] = RList[1];
            }
            pRightUp.MouseWheel += PRightUpHMouseWheel;
        }

        private void bRightUp4_Click(object sender, EventArgs e)
        {
            pRightUp.MouseWheel -= PRightUpHMouseWheel;
            GetParam();
            List<double> RList = GetInterPoint1(RightUpImage, hwindow[1], RightUpRowCross, RightUpColCross);

            if (RList.Count == 2)
            {
                tbRightUpRow4.Text = RList[0].ToString();
                tbRightUpCol4.Text = RList[1].ToString();
                RightUpRowCross[3] = RList[0];
                RightUpColCross[3] = RList[1];
            }
            pRightUp.MouseWheel += PRightUpHMouseWheel;
        }
        private void bRightUp5_Click(object sender, EventArgs e)
        {
            pRightUp.MouseWheel -= PRightUpHMouseWheel;
            GetParam();
            List<double> RList = GetInterPoint1(RightUpImage, hwindow[1], RightUpRowCross, RightUpColCross);

            if (RList.Count == 2)
            {
                tbRightUpRow5.Text = RList[0].ToString();
                tbRightUpCol5.Text = RList[1].ToString();
                RightUpRowCross[4] = RList[0];
                RightUpColCross[4] = RList[1];
            }
            pRightUp.MouseWheel += PRightUpHMouseWheel;
        }
        private void bRightUp6_Click(object sender, EventArgs e)
        {
            pRightUp.MouseWheel -= PRightUpHMouseWheel;
            GetParam();
            List<double> RList = GetInterPoint1(RightUpImage, hwindow[1], RightUpRowCross, RightUpColCross);

            if (RList.Count == 2)
            {
                tbRightUpRow6.Text = RList[0].ToString();
                tbRightUpCol6.Text = RList[1].ToString();
                RightUpRowCross[5] = RList[0];
                RightUpColCross[5] = RList[1];
            }
            pRightUp.MouseWheel += PRightUpHMouseWheel;
        }
        private void bRightUp7_Click(object sender, EventArgs e)
        {
            pRightUp.MouseWheel -= PRightUpHMouseWheel;
            GetParam();
            List<double> RList = GetInterPoint1(RightUpImage, hwindow[1], RightUpRowCross, RightUpColCross);

            if (RList.Count == 2)
            {
                tbRightUpRow7.Text = RList[0].ToString();
                tbRightUpCol7.Text = RList[1].ToString();
                RightUpRowCross[6] = RList[0];
                RightUpColCross[6] = RList[1];
            }
            pRightUp.MouseWheel += PRightUpHMouseWheel;
        }

        private void bRightUp8_Click(object sender, EventArgs e)
        {
            pRightUp.MouseWheel -= PRightUpHMouseWheel;
            GetParam();
            List<double> RList = GetInterPoint1(RightUpImage, hwindow[1], RightUpRowCross, RightUpColCross);

            if (RList.Count == 2)
            {
                tbRightUpRow8.Text = RList[0].ToString();
                tbRightUpCol8.Text = RList[1].ToString();
                RightUpRowCross[7] = RList[0];
                RightUpColCross[7] = RList[1];
            }
            pRightUp.MouseWheel += PRightUpHMouseWheel;
        }
        private void bRightUp9_Click(object sender, EventArgs e)
        {
            pRightUp.MouseWheel -= PRightUpHMouseWheel;
            GetParam();
            List<double> RList = GetInterPoint1(RightUpImage, hwindow[1], RightUpRowCross, RightUpColCross);

            if (RList.Count == 2)
            {
                tbRightUpRow9.Text = RList[0].ToString();
                tbRightUpCol9.Text = RList[1].ToString();
                RightUpRowCross[8] = RList[0];
                RightUpColCross[8] = RList[1];
            }
            pRightUp.MouseWheel += PRightUpHMouseWheel;
        }

        private void button19_Click(object sender, EventArgs e)
        {
            //右上相机
            double[] Row = new double[9]; double[] Col = new double[9];
            double[] RowPhy = new double[9]; double[] ColPhy = new double[9];

            //图像坐标
            Row[0] = double.Parse(tbRightUpRow1.Text);
            Row[1] = double.Parse(tbRightUpRow2.Text);
            Row[2] = double.Parse(tbRightUpRow3.Text);
            Row[3] = double.Parse(tbRightUpRow4.Text);
            Row[4] = double.Parse(tbRightUpRow5.Text);
            Row[5] = double.Parse(tbRightUpRow6.Text);
            Row[6] = double.Parse(tbRightUpRow7.Text);
            Row[7] = double.Parse(tbRightUpRow8.Text);
            Row[8] = double.Parse(tbRightUpRow9.Text);
            Col[0] = double.Parse(tbRightUpCol1.Text);
            Col[1] = double.Parse(tbRightUpCol2.Text);
            Col[2] = double.Parse(tbRightUpCol3.Text);
            Col[3] = double.Parse(tbRightUpCol4.Text);
            Col[4] = double.Parse(tbRightUpCol5.Text);
            Col[5] = double.Parse(tbRightUpCol6.Text);
            Col[6] = double.Parse(tbRightUpCol7.Text);
            Col[7] = double.Parse(tbRightUpCol8.Text);
            Col[8] = double.Parse(tbRightUpCol9.Text);
            //世界坐标
            RowPhy[0] = double.Parse(tbRightUpY1.Text);
            RowPhy[1] = double.Parse(tbRightUpY2.Text);
            RowPhy[2] = double.Parse(tbRightUpY3.Text);
            RowPhy[3] = double.Parse(tbRightUpY4.Text);
            RowPhy[4] = double.Parse(tbRightUpY5.Text);
            RowPhy[5] = double.Parse(tbRightUpY6.Text);
            RowPhy[6] = double.Parse(tbRightUpY7.Text);
            RowPhy[7] = double.Parse(tbRightUpY8.Text);
            RowPhy[8] = double.Parse(tbRightUpY9.Text);
            ColPhy[0] = double.Parse(tbRightUpX1.Text);
            ColPhy[1] = double.Parse(tbRightUpX2.Text);
            ColPhy[2] = double.Parse(tbRightUpX3.Text);
            ColPhy[3] = double.Parse(tbRightUpX4.Text);
            ColPhy[4] = double.Parse(tbRightUpX5.Text);
            ColPhy[5] = double.Parse(tbRightUpX6.Text);
            ColPhy[6] = double.Parse(tbRightUpX7.Text);
            ColPhy[7] = double.Parse(tbRightUpX8.Text);
            ColPhy[8] = double.Parse(tbRightUpX9.Text);

            if (PublicSet.Myset.DetectMode == "3相机正负单测" && NOrP == "N")
            {
                string path = PublicSet.path + "\\矩阵文件\\2负极左上相机.tup";
                //生成转换矩阵
                HOperatorSet.VectorToHomMat2d(Row, Col, RowPhy, ColPhy, out PublicSet.NRightUpHomMat2D);
                //保存矩阵
                HOperatorSet.WriteTuple(PublicSet.NRightUpHomMat2D, path); return;
            }
            else if (PublicSet.Myset.DetectMode == "3相机正负单测")
            {
                string path = PublicSet.path + "\\矩阵文件\\2正极左上相机.tup";
                //生成转换矩阵
                HOperatorSet.VectorToHomMat2d(Row, Col, RowPhy, ColPhy, out PublicSet.PLeftUpHomMat2D);
                //保存矩阵
                HOperatorSet.WriteTuple(PublicSet.PLeftUpHomMat2D, path); return;
            }


            if (NOrP == "N")
            {
                string path = PublicSet.path + "\\矩阵文件\\2负极右上相机.tup";
                //生成转换矩阵
                HOperatorSet.VectorToHomMat2d(Row, Col, RowPhy, ColPhy, out PublicSet.NRightUpHomMat2D);
                //保存矩阵
                HOperatorSet.WriteTuple(PublicSet.NRightUpHomMat2D, path);
            }
            else
            {
                string path = PublicSet.path + "\\矩阵文件\\6正极右上相机.tup";
                //生成转换矩阵
                HOperatorSet.VectorToHomMat2d(Row, Col, RowPhy, ColPhy, out PublicSet.PRightUpHomMat2D);
                //保存矩阵
                HOperatorSet.WriteTuple(PublicSet.PRightUpHomMat2D, path);
            }
            ToastNotification.Show("成功");
        }
        private void button18_Click(object sender, EventArgs e)
        {
            //右上相机验证矩阵
            GetParam();
            List<double> RList = GetInterPoint1(RightUpImage, hwindow[1], RightUpRowCross, RightUpColCross);
            if (RList.Count == 2)
            {
                HOperatorSet.AffineTransPoint2d((NOrP == "N" ? PublicSet.NRightUpHomMat2D : PublicSet.PRightUpHomMat2D), RList[0], RList[1], out HTuple PhyY, out HTuple PhyX);
                hwindow[1].NewLine();
                HOperatorSet.WriteString(hwindow[1], "物理坐标X:" + PhyX.D.ToString("0.000") + "Y:" + PhyY);
            }
            else
            {
                ToastNotification.Show("未得到横竖线交点，无法验证！");
            }
        }
        #endregion

        #region 左下相机
        private void PLeftDownHMouseWheel(object sender, MouseEventArgs e)
        {
            if (LeftDownImage != null && LeftDownImage.IsInitialized())
            {
                Tool.HMouseWheel(e, hwindow[2], LeftDownImage);
                for (int i = 0; i < 8; ++i)
                {
                    HOperatorSet.DispCross(hwindow[2], LeftDownRowCross[i], LeftDownColCross[i], 30, 0);
                }
            }
        }


        private void pLeftDown_MouseMove(object sender, MouseEventArgs e)
        {

        }

        private void pLeftDown_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                if (LeftDownImage != null && LeftDownImage.IsInitialized())
                {
                    //try
                    //{
                    //    hwindow[2].GetMposition(out int row, out int column, out _);
                    //    Tool.RowDown = row;    //鼠标按下时的行坐标
                    //    Tool.ColDown = column; //鼠标按下时的列坐标
                    //    Tool.IsEventArgs = true;//记录鼠标按下
                    //}
                    //catch (Exception)
                    //{
                    //}
                }
                if (e.Clicks == 2)
                {
                    if (LeftDownImage != null && LeftDownImage.IsInitialized())
                    {
                        HOperatorSet.GetImageSize(LeftDownImage, out HTuple width, out HTuple height);
                        HOperatorSet.SetPart(hwindow[2], 0, 0, height.I, width.I);
                        HOperatorSet.DispObj(LeftDownImage, hwindow[2]);
                        for (int i = 0; i < 8; ++i)
                        {
                            HOperatorSet.DispCross(hwindow[2], LeftDownRowCross[i], LeftDownColCross[i], 30, 0);
                        }
                    }
                }
            }
        }

        private void pLeftDown_MouseUp(object sender, MouseEventArgs e)
        {
            Tool.IsEventArgs = false;//记录鼠标抬起后，移动图像
        }

        private void bLeftDown1_Click(object sender, EventArgs e)
        {
            pLeftDown.MouseWheel -= PLeftDownHMouseWheel;
            GetParam();
            List<double> RList = GetInterPoint1(LeftDownImage, hwindow[2], LeftDownRowCross, LeftDownColCross);

            if (RList.Count == 2)
            {
                tbLeftDownRow1.Text = RList[0].ToString();
                tbLeftDownCol1.Text = RList[1].ToString();
                LeftDownRowCross[0] = RList[0];
                LeftDownColCross[0] = RList[1];

            }
            pLeftDown.MouseWheel += PLeftDownHMouseWheel;
        }

        private void bLeftDown2_Click(object sender, EventArgs e)
        {
            pLeftDown.MouseWheel -= PLeftDownHMouseWheel;
            GetParam();
            List<double> RList = GetInterPoint1(LeftDownImage, hwindow[2], LeftDownRowCross, LeftDownColCross);

            if (RList.Count == 2)
            {
                tbLeftDownRow2.Text = RList[0].ToString();
                tbLeftDownCol2.Text = RList[1].ToString();
                LeftDownRowCross[1] = RList[0];
                LeftDownColCross[1] = RList[1];
            }
            pLeftDown.MouseWheel += PLeftDownHMouseWheel;
        }

        private void bLeftDown3_Click(object sender, EventArgs e)
        {
            pLeftDown.MouseWheel -= PLeftDownHMouseWheel;
            GetParam();
            List<double> RList = GetInterPoint1(LeftDownImage, hwindow[2], LeftDownRowCross, LeftDownColCross);

            if (RList.Count == 2)
            {
                tbLeftDownRow3.Text = RList[0].ToString();
                tbLeftDownCol3.Text = RList[1].ToString();
                LeftDownRowCross[2] = RList[0];
                LeftDownColCross[2] = RList[1];
                if (!tbPointX.Text.Equals("") && !tbPointY.Text.Equals("") && !tbLeftDownCol1.Text.Equals("") && !tbLeftDownRow1.Text.Equals("") && !tbLeftDownCol2.Text.Equals("") && !tbLeftDownRow2.Text.Equals(""))
                {
                    int x, y;
                    GetPoint9(LeftDownRowCross[0], LeftDownColCross[0], LeftDownRowCross[1], LeftDownColCross[1], LeftDownRowCross[2], LeftDownColCross[2], Convert.ToInt32(tbLeftDownX1.Text), Convert.ToInt32(tbLeftDownY1.Text), Convert.ToInt32(tbLeftDownX2.Text), out x, out y);
                    tbLeftDownX3.Text = x.ToString();
                    tbLeftDownY3.Text = y.ToString();
                }
            }
            pLeftDown.MouseWheel += PLeftDownHMouseWheel;
        }

        private void bLeftDown4_Click(object sender, EventArgs e)
        {
            pLeftDown.MouseWheel -= PLeftDownHMouseWheel;
            GetParam();
            List<double> RList = GetInterPoint1(LeftDownImage, hwindow[2], LeftDownRowCross, LeftDownColCross);

            if (RList.Count == 2)
            {
                tbLeftDownRow4.Text = RList[0].ToString();
                tbLeftDownCol4.Text = RList[1].ToString();
                LeftDownRowCross[3] = RList[0];
                LeftDownColCross[3] = RList[1];
                if (!tbPointX.Text.Equals("") && !tbPointY.Text.Equals("") && !tbLeftDownCol1.Text.Equals("") && !tbLeftDownRow1.Text.Equals("") && !tbLeftDownCol2.Text.Equals("") && !tbLeftDownRow2.Text.Equals(""))
                {
                    int x, y;
                    GetPoint9(LeftDownRowCross[0], LeftDownColCross[0], LeftDownRowCross[1], LeftDownColCross[1], LeftDownRowCross[3], LeftDownColCross[3], Convert.ToInt32(tbLeftDownX1.Text), Convert.ToInt32(tbLeftDownY1.Text), Convert.ToInt32(tbLeftDownX2.Text), out x, out y);
                    tbLeftDownX4.Text = x.ToString();
                    tbLeftDownY4.Text = y.ToString();
                }
            }
            pLeftDown.MouseWheel += PLeftDownHMouseWheel;
        }

        private void bLeftDown5_Click(object sender, EventArgs e)
        {
            pLeftDown.MouseWheel -= PLeftDownHMouseWheel;
            GetParam();
            List<double> RList = GetInterPoint1(LeftDownImage, hwindow[2], LeftDownRowCross, LeftDownColCross);

            if (RList.Count == 2)
            {
                tbLeftDownRow5.Text = RList[0].ToString();
                tbLeftDownCol5.Text = RList[1].ToString();
                LeftDownRowCross[4] = RList[0];
                LeftDownColCross[4] = RList[1];
                if (!tbPointX.Text.Equals("") && !tbPointY.Text.Equals("") && !tbLeftDownCol1.Text.Equals("") && !tbLeftDownRow1.Text.Equals("") && !tbLeftDownCol2.Text.Equals("") && !tbLeftDownRow2.Text.Equals(""))
                {
                    int x, y;
                    GetPoint9(LeftDownRowCross[0], LeftDownColCross[0], LeftDownRowCross[1], LeftDownColCross[1], LeftDownRowCross[4], LeftDownColCross[4], Convert.ToInt32(tbLeftDownX1.Text), Convert.ToInt32(tbLeftDownY1.Text), Convert.ToInt32(tbLeftDownX2.Text), out x, out y);
                    tbLeftDownX5.Text = x.ToString();
                    tbLeftDownY5.Text = y.ToString();
                }
            }
            pLeftDown.MouseWheel += PLeftDownHMouseWheel;
        }

        private void bLeftDown6_Click(object sender, EventArgs e)
        {
            pLeftDown.MouseWheel -= PLeftDownHMouseWheel;
            GetParam();
            List<double> RList = GetInterPoint1(LeftDownImage, hwindow[2], LeftDownRowCross, LeftDownColCross);

            if (RList.Count == 2)
            {
                tbLeftDownRow6.Text = RList[0].ToString();
                tbLeftDownCol6.Text = RList[1].ToString();
                LeftDownRowCross[5] = RList[0];
                LeftDownColCross[5] = RList[1];
                if (!tbPointX.Text.Equals("") && !tbPointY.Text.Equals("") && !tbLeftDownCol1.Text.Equals("") && !tbLeftDownRow1.Text.Equals("") && !tbLeftDownCol2.Text.Equals("") && !tbLeftDownRow2.Text.Equals(""))
                {
                    int x, y;
                    GetPoint9(LeftDownRowCross[0], LeftDownColCross[0], LeftDownRowCross[1], LeftDownColCross[1], LeftDownRowCross[5], LeftDownColCross[5], Convert.ToInt32(tbLeftDownX1.Text), Convert.ToInt32(tbLeftDownY1.Text), Convert.ToInt32(tbLeftDownX2.Text), out x, out y);
                    tbLeftDownX6.Text = x.ToString();
                    tbLeftDownY6.Text = y.ToString();
                }
            }
            pLeftDown.MouseWheel += PLeftDownHMouseWheel;
        }

        private void bLeftDown7_Click(object sender, EventArgs e)
        {
            pLeftDown.MouseWheel -= PLeftDownHMouseWheel;
            GetParam();
            List<double> RList = GetInterPoint1(LeftDownImage, hwindow[2], LeftDownRowCross, LeftDownColCross);

            if (RList.Count == 2)
            {
                tbLeftDownRow7.Text = RList[0].ToString();
                tbLeftDownCol7.Text = RList[1].ToString();
                LeftDownRowCross[6] = RList[0];
                LeftDownColCross[6] = RList[1];
                if (!tbPointX.Text.Equals("") && !tbPointY.Text.Equals("") && !tbLeftDownCol1.Text.Equals("") && !tbLeftDownRow1.Text.Equals("") && !tbLeftDownCol2.Text.Equals("") && !tbLeftDownRow2.Text.Equals(""))
                {
                    int x, y;
                    GetPoint9(LeftDownRowCross[0], LeftDownColCross[0], LeftDownRowCross[1], LeftDownColCross[1], LeftDownRowCross[6], LeftDownColCross[6], Convert.ToInt32(tbLeftDownX1.Text), Convert.ToInt32(tbLeftDownY1.Text), Convert.ToInt32(tbLeftDownX2.Text), out x, out y);
                    tbLeftDownX7.Text = x.ToString();
                    tbLeftDownY7.Text = y.ToString();
                }
            }
            pLeftDown.MouseWheel += PLeftDownHMouseWheel;
        }

        private void bLeftDown8_Click(object sender, EventArgs e)
        {
            pLeftDown.MouseWheel -= PLeftDownHMouseWheel;
            GetParam();
            List<double> RList = GetInterPoint1(LeftDownImage, hwindow[2], LeftDownRowCross, LeftDownColCross);

            if (RList.Count == 2)
            {
                tbLeftDownRow8.Text = RList[0].ToString();
                tbLeftDownCol8.Text = RList[1].ToString();
                LeftDownRowCross[7] = RList[0];
                LeftDownColCross[7] = RList[1];
                if (!tbPointX.Text.Equals("") && !tbPointY.Text.Equals("") && !tbLeftDownCol1.Text.Equals("") && !tbLeftDownRow1.Text.Equals("") && !tbLeftDownCol2.Text.Equals("") && !tbLeftDownRow2.Text.Equals(""))
                {
                    int x, y;
                    GetPoint9(LeftDownRowCross[0], LeftDownColCross[0], LeftDownRowCross[1], LeftDownColCross[1], LeftDownRowCross[7], LeftDownColCross[7], Convert.ToInt32(tbLeftDownX1.Text), Convert.ToInt32(tbLeftDownY1.Text), Convert.ToInt32(tbLeftDownX2.Text), out x, out y);
                    tbLeftDownX8.Text = x.ToString();
                    tbLeftDownY8.Text = y.ToString();
                }
            }
            pLeftDown.MouseWheel += PLeftDownHMouseWheel;
        }

        private void bLeftDown9_Click(object sender, EventArgs e)
        {
            pLeftDown.MouseWheel -= PLeftDownHMouseWheel;
            GetParam();
            List<double> RList = GetInterPoint1(LeftDownImage, hwindow[2], LeftDownRowCross, LeftDownColCross);

            if (RList.Count == 2)
            {
                tbLeftDownRow9.Text = RList[0].ToString();
                tbLeftDownCol9.Text = RList[1].ToString();
                LeftDownRowCross[8] = RList[0];
                LeftDownColCross[8] = RList[1];
                if (!tbPointX.Text.Equals("") && !tbPointY.Text.Equals("") && !tbLeftDownCol1.Text.Equals("") && !tbLeftDownRow1.Text.Equals("") && !tbLeftDownCol2.Text.Equals("") && !tbLeftDownRow2.Text.Equals(""))
                {
                    int x, y;
                    GetPoint9(LeftDownRowCross[0], LeftDownColCross[0], LeftDownRowCross[1], LeftDownColCross[1], LeftDownRowCross[8], LeftDownColCross[8], Convert.ToInt32(tbLeftDownX1.Text), Convert.ToInt32(tbLeftDownY1.Text), Convert.ToInt32(tbLeftDownX2.Text), out x, out y);
                    tbLeftDownX9.Text = x.ToString();
                    tbLeftDownY9.Text = y.ToString();
                }
            }
            pLeftDown.MouseWheel += PLeftDownHMouseWheel;
        }

        private void button8_Click(object sender, EventArgs e)
        {
            //左下相机
            double[] Row = new double[9]; double[] Col = new double[9];
            double[] RowPhy = new double[9]; double[] ColPhy = new double[9];

            //图像坐标
            Row[0] = double.Parse(tbLeftDownRow1.Text);
            Row[1] = double.Parse(tbLeftDownRow2.Text);
            Row[2] = double.Parse(tbLeftDownRow3.Text);
            Row[3] = double.Parse(tbLeftDownRow4.Text);
            Row[4] = double.Parse(tbLeftDownRow5.Text);
            Row[5] = double.Parse(tbLeftDownRow6.Text);
            Row[6] = double.Parse(tbLeftDownRow7.Text);
            Row[7] = double.Parse(tbLeftDownRow8.Text);
            Row[8] = double.Parse(tbLeftDownRow9.Text);
            Col[0] = double.Parse(tbLeftDownCol1.Text);
            Col[1] = double.Parse(tbLeftDownCol2.Text);
            Col[2] = double.Parse(tbLeftDownCol3.Text);
            Col[3] = double.Parse(tbLeftDownCol4.Text);
            Col[4] = double.Parse(tbLeftDownCol5.Text);
            Col[5] = double.Parse(tbLeftDownCol6.Text);
            Col[6] = double.Parse(tbLeftDownCol7.Text);
            Col[7] = double.Parse(tbLeftDownCol8.Text);
            Col[8] = double.Parse(tbLeftDownCol9.Text);
            //世界坐标
            RowPhy[0] = double.Parse(tbLeftDownY1.Text);
            RowPhy[1] = double.Parse(tbLeftDownY2.Text);
            RowPhy[2] = double.Parse(tbLeftDownY3.Text);
            RowPhy[3] = double.Parse(tbLeftDownY4.Text);
            RowPhy[4] = double.Parse(tbLeftDownY5.Text);
            RowPhy[5] = double.Parse(tbLeftDownY6.Text);
            RowPhy[6] = double.Parse(tbLeftDownY7.Text);
            RowPhy[7] = double.Parse(tbLeftDownY8.Text);
            RowPhy[8] = double.Parse(tbLeftDownY9.Text);
            ColPhy[0] = double.Parse(tbLeftDownX1.Text);
            ColPhy[1] = double.Parse(tbLeftDownX2.Text);
            ColPhy[2] = double.Parse(tbLeftDownX3.Text);
            ColPhy[3] = double.Parse(tbLeftDownX4.Text);
            ColPhy[4] = double.Parse(tbLeftDownX5.Text);
            ColPhy[5] = double.Parse(tbLeftDownX6.Text);
            ColPhy[6] = double.Parse(tbLeftDownX7.Text);
            ColPhy[7] = double.Parse(tbLeftDownX8.Text);
            ColPhy[8] = double.Parse(tbLeftDownX9.Text);

            if (PublicSet.Myset.DetectMode == "3相机正负单测" && NOrP == "N")
            {
                string path = PublicSet.path + "\\矩阵文件\\3负极左上相机.tup";
                //生成转换矩阵
                HOperatorSet.VectorToHomMat2d(Row, Col, RowPhy, ColPhy, out PublicSet.NLeftDownHomMat2D);
                //保存矩阵
                HOperatorSet.WriteTuple(PublicSet.NLeftDownHomMat2D, path); return;
            }
            else if (PublicSet.Myset.DetectMode == "3相机正负单测")
            {
                string path = PublicSet.path + "\\矩阵文件\\3正极左上相机.tup";
                //生成转换矩阵
                HOperatorSet.VectorToHomMat2d(Row, Col, RowPhy, ColPhy, out PublicSet.PLeftDownHomMat2D);
                //保存矩阵
                HOperatorSet.WriteTuple(PublicSet.PLeftDownHomMat2D, path); return;
            }


            if (NOrP == "N")
            {
                string path = PublicSet.path + "\\矩阵文件\\3负极左下相机.tup";
                //生成转换矩阵
                HOperatorSet.VectorToHomMat2d(Row, Col, RowPhy, ColPhy, out PublicSet.NLeftDownHomMat2D);
                //保存矩阵
                HOperatorSet.WriteTuple(PublicSet.NLeftDownHomMat2D, path);
            }
            else
            {
                string path = PublicSet.path + "\\矩阵文件\\7正极左下相机.tup";
                //生成转换矩阵
                HOperatorSet.VectorToHomMat2d(Row, Col, RowPhy, ColPhy, out PublicSet.PLeftDownHomMat2D);
                //保存矩阵
                HOperatorSet.WriteTuple(PublicSet.PLeftDownHomMat2D, path);
            }
            ToastNotification.Show("成功");
        }
        private void button7_Click(object sender, EventArgs e)
        {
            //左下相机验证矩阵
            GetParam();
            List<double> RList = GetInterPoint1(LeftDownImage, hwindow[2], LeftDownRowCross, LeftDownColCross);
            if (RList.Count == 2)
            {
                HOperatorSet.AffineTransPoint2d((NOrP == "N" ? PublicSet.NLeftDownHomMat2D : PublicSet.PLeftDownHomMat2D), RList[0], RList[1], out HTuple PhyY, out HTuple PhyX);
                hwindow[2].NewLine();
                HOperatorSet.WriteString(hwindow[2], "物理坐标X:" + PhyX.D.ToString("0.000") + "Y:" + PhyY.D.ToString("0.000"));
            }
            else
            {
                ToastNotification.Show("未得到横竖线交点，无法验证！");
            }
        }

        #endregion

        #region 右下相机
        private void PRightDownHMouseWheel(object sender, MouseEventArgs e)
        {
            if (RightDownImage != null && RightDownImage.IsInitialized())
            {
                Tool.HMouseWheel(e, hwindow[3], RightDownImage);
                for (int i = 0; i < 8; ++i)
                {
                    HOperatorSet.DispCross(hwindow[3], RightDownRowCross[i], RightDownColCross[i], 30, 0);
                }
            }
        }

        private void pRightDown_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                if (RightDownImage != null && RightDownImage.IsInitialized())
                {
                    //try
                    //{
                    //    hwindow[3].GetMposition(out int row, out int column, out _);
                    //    Tool.RowDown = row;    //鼠标按下时的行坐标
                    //    Tool.ColDown = column; //鼠标按下时的列坐标
                    //    Tool.IsEventArgs = true;//记录鼠标按下
                    //}
                    //catch (Exception)
                    //{
                    //}
                }
                if (e.Clicks == 2)
                {
                    if (RightDownImage != null && RightDownImage.IsInitialized())
                    {
                        HOperatorSet.GetImageSize(RightDownImage, out HTuple width, out HTuple height);
                        HOperatorSet.SetPart(hwindow[3], 0, 0, height.I, width.I);
                        HOperatorSet.DispObj(RightDownImage, hwindow[3]);
                        for (int i = 0; i < 8; ++i)
                        {
                            HOperatorSet.DispCross(hwindow[3], RightDownRowCross[i], RightDownColCross[i], 30, 0);
                        }
                    }
                }
            }
        }

        private void pRightDown_MouseUp(object sender, MouseEventArgs e)
        {
            Tool.IsEventArgs = false;//记录鼠标抬起后，移动图像
        }


        private void bRightDown1_Click(object sender, EventArgs e)
        {
            pRightDown.MouseWheel -= PRightDownHMouseWheel;
            GetParam();
            List<double> RList = GetInterPoint1(RightDownImage, hwindow[3], RightDownRowCross, RightDownColCross);

            if (RList.Count == 2)
            {
                tbRightDownRow1.Text = RList[0].ToString();
                tbRightDownCol1.Text = RList[1].ToString();
                RightDownRowCross[0] = RList[0];
                RightDownColCross[0] = RList[1];
            }
            pRightDown.MouseWheel += PRightDownHMouseWheel;
        }

        private void bRightDown2_Click(object sender, EventArgs e)
        {
            pRightDown.MouseWheel -= PRightDownHMouseWheel;
            GetParam();
            List<double> RList = GetInterPoint1(RightDownImage, hwindow[3], RightDownRowCross, RightDownColCross);

            if (RList.Count == 2)
            {
                tbRightDownRow2.Text = RList[0].ToString();
                tbRightDownCol2.Text = RList[1].ToString();
                RightDownRowCross[1] = RList[0];
                RightDownColCross[1] = RList[1];
            }
            pRightDown.MouseWheel += PRightDownHMouseWheel;
        }

        private void bRightDown3_Click(object sender, EventArgs e)
        {
            pRightDown.MouseWheel -= PRightDownHMouseWheel;
            GetParam();
            List<double> RList = GetInterPoint1(RightDownImage, hwindow[3], RightDownRowCross, RightDownColCross);

            if (RList.Count == 2)
            {
                tbRightDownRow3.Text = RList[0].ToString();
                tbRightDownCol3.Text = RList[1].ToString();
                RightDownRowCross[2] = RList[0];
                RightDownColCross[2] = RList[1];
            }
            pRightDown.MouseWheel += PRightDownHMouseWheel;
        }

        private void bRightDown4_Click(object sender, EventArgs e)
        {
            pRightDown.MouseWheel -= PRightDownHMouseWheel;
            GetParam();
            List<double> RList = GetInterPoint1(RightDownImage, hwindow[3], RightDownRowCross, RightDownColCross);

            if (RList.Count == 2)
            {
                tbRightDownRow4.Text = RList[0].ToString();
                tbRightDownCol4.Text = RList[1].ToString();
                RightDownRowCross[3] = RList[0];
                RightDownColCross[3] = RList[1];
            }
            pRightDown.MouseWheel += PRightDownHMouseWheel;
        }

        private void bRightDown5_Click(object sender, EventArgs e)
        {
            pRightDown.MouseWheel -= PRightDownHMouseWheel;
            GetParam();
            List<double> RList = GetInterPoint1(RightDownImage, hwindow[3], RightDownRowCross, RightDownColCross);

            if (RList.Count == 2)
            {
                tbRightDownRow5.Text = RList[0].ToString();
                tbRightDownCol5.Text = RList[1].ToString();
                RightDownRowCross[4] = RList[0];
                RightDownColCross[4] = RList[1];
            }
            pRightDown.MouseWheel += PRightDownHMouseWheel;
        }
        private void bRightDown6_Click(object sender, EventArgs e)
        {
            pRightDown.MouseWheel -= PRightDownHMouseWheel;
            GetParam();
            List<double> RList = GetInterPoint1(RightDownImage, hwindow[3], RightDownRowCross, RightDownColCross);

            if (RList.Count == 2)
            {
                tbRightDownRow6.Text = RList[0].ToString();
                tbRightDownCol6.Text = RList[1].ToString();
                RightDownRowCross[5] = RList[0];
                RightDownColCross[5] = RList[1];
            }
            pRightDown.MouseWheel += PRightDownHMouseWheel;
        }
        private void bRightDown7_Click(object sender, EventArgs e)
        {
            pRightDown.MouseWheel -= PRightDownHMouseWheel;
            GetParam();
            List<double> RList = GetInterPoint1(RightDownImage, hwindow[3], RightDownRowCross, RightDownColCross);

            if (RList.Count == 2)
            {
                tbRightDownRow7.Text = RList[0].ToString();
                tbRightDownCol7.Text = RList[1].ToString();
                RightDownRowCross[6] = RList[0];
                RightDownColCross[6] = RList[1];
            }
            pRightDown.MouseWheel += PRightDownHMouseWheel;
        }
        private void bRightDown8_Click(object sender, EventArgs e)
        {
            pRightDown.MouseWheel -= PRightDownHMouseWheel;
            GetParam();
            List<double> RList = GetInterPoint1(RightDownImage, hwindow[3], RightDownRowCross, RightDownColCross);

            if (RList.Count == 2)
            {
                tbRightDownRow8.Text = RList[0].ToString();
                tbRightDownCol8.Text = RList[1].ToString();
                RightDownRowCross[7] = RList[0];
                RightDownColCross[7] = RList[1];
            }
            pRightDown.MouseWheel += PRightDownHMouseWheel;
        }
        private void bRightDown9_Click(object sender, EventArgs e)
        {
            pRightDown.MouseWheel -= PRightDownHMouseWheel;
            GetParam();
            List<double> RList = GetInterPoint1(RightDownImage, hwindow[3], RightDownRowCross, RightDownColCross);

            if (RList.Count == 2)
            {
                tbRightDownRow9.Text = RList[0].ToString();
                tbRightDownCol9.Text = RList[1].ToString();
                RightDownRowCross[8] = RList[0];
                RightDownColCross[8] = RList[1];
            }
            pRightDown.MouseWheel += PRightDownHMouseWheel;
        }


        private void button30_Click(object sender, EventArgs e)
        {//右下相机
            double[] Row = new double[9]; double[] Col = new double[9];
            double[] RowPhy = new double[9]; double[] ColPhy = new double[9];

            //图像坐标
            Row[0] = double.Parse(tbRightDownRow1.Text);
            Row[1] = double.Parse(tbRightDownRow2.Text);
            Row[2] = double.Parse(tbRightDownRow3.Text);
            Row[3] = double.Parse(tbRightDownRow4.Text);
            Row[4] = double.Parse(tbRightDownRow5.Text);
            Row[5] = double.Parse(tbRightDownRow6.Text);
            Row[6] = double.Parse(tbRightDownRow7.Text);
            Row[7] = double.Parse(tbRightDownRow8.Text);
            Row[8] = double.Parse(tbRightDownRow9.Text);
            Col[0] = double.Parse(tbRightDownCol1.Text);
            Col[1] = double.Parse(tbRightDownCol2.Text);
            Col[2] = double.Parse(tbRightDownCol3.Text);
            Col[3] = double.Parse(tbRightDownCol4.Text);
            Col[4] = double.Parse(tbRightDownCol5.Text);
            Col[5] = double.Parse(tbRightDownCol6.Text);
            Col[6] = double.Parse(tbRightDownCol7.Text);
            Col[7] = double.Parse(tbRightDownCol8.Text);
            Col[8] = double.Parse(tbRightDownCol9.Text);
            //世界坐标
            RowPhy[0] = double.Parse(tbRightDownY1.Text);
            RowPhy[1] = double.Parse(tbRightDownY2.Text);
            RowPhy[2] = double.Parse(tbRightDownY3.Text);
            RowPhy[3] = double.Parse(tbRightDownY4.Text);
            RowPhy[4] = double.Parse(tbRightDownY5.Text);
            RowPhy[5] = double.Parse(tbRightDownY6.Text);
            RowPhy[6] = double.Parse(tbRightDownY7.Text);
            RowPhy[7] = double.Parse(tbRightDownY8.Text);
            RowPhy[8] = double.Parse(tbRightDownY9.Text);
            ColPhy[0] = double.Parse(tbRightDownX1.Text);
            ColPhy[1] = double.Parse(tbRightDownX2.Text);
            ColPhy[2] = double.Parse(tbRightDownX3.Text);
            ColPhy[3] = double.Parse(tbRightDownX4.Text);
            ColPhy[4] = double.Parse(tbRightDownX5.Text);
            ColPhy[5] = double.Parse(tbRightDownX6.Text);
            ColPhy[6] = double.Parse(tbRightDownX7.Text);
            ColPhy[7] = double.Parse(tbRightDownX8.Text);
            ColPhy[8] = double.Parse(tbRightDownX9.Text);
            if (NOrP == "N")
            {
                string path = PublicSet.path + "\\矩阵文件\\4负极右下相机.tup";
                //生成转换矩阵
                HOperatorSet.VectorToHomMat2d(Row, Col, RowPhy, ColPhy, out PublicSet.NRightDownHomMat2D);
                //保存矩阵
                HOperatorSet.WriteTuple(PublicSet.NRightDownHomMat2D, path);

            }
            else
            {
                string path = PublicSet.path + "\\矩阵文件\\8正极右下相机.tup";
                //生成转换矩阵
                HOperatorSet.VectorToHomMat2d(Row, Col, RowPhy, ColPhy, out PublicSet.PRightDownHomMat2D);
                //保存矩阵
                HOperatorSet.WriteTuple(PublicSet.PRightDownHomMat2D, path);
            }
            ToastNotification.Show("成功");
        }

        private void button29_Click(object sender, EventArgs e)
        {
            //右下相机验证矩阵
            GetParam();
            List<double> RList = GetInterPoint1(RightDownImage, hwindow[3], RightDownRowCross, RightDownColCross);
            if (RList.Count == 2)
            {
                HOperatorSet.AffineTransPoint2d(NOrP == "N" ? PublicSet.NRightDownHomMat2D : PublicSet.PRightDownHomMat2D, RList[0], RList[1], out HTuple PhyY, out HTuple PhyX);
                hwindow[3].NewLine();
                HOperatorSet.WriteString(hwindow[3], "物理坐标X:" + PhyX.D.ToString("0.000") + "Y:" + PhyY.D.ToString("0.000"));
            }
            else
            {
                ToastNotification.Show("未得到横竖线交点，无法验证！");
            }
        }
        #endregion

        private void bMinimized_Click(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Minimized;
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (!tbPointX.Text.Equals("") && !tbPointY.Text.Equals("") && !tbLeftDownCol1.Text.Equals("") && !tbLeftDownRow1.Text.Equals("") && !tbLeftDownCol2.Text.Equals("") && !tbLeftDownRow2.Text.Equals(""))
            {
                int x, y;
                GetPoint9(LeftDownRowCross[0], LeftDownColCross[0], LeftDownRowCross[1], LeftDownColCross[1], LeftDownRowCross[2], LeftDownColCross[2], Convert.ToInt32(tbLeftDownX1.Text), Convert.ToInt32(tbLeftDownY1.Text), Convert.ToInt32(tbLeftDownX2.Text), out x, out y);
                tbLeftDownX3.Text = x.ToString();
                tbLeftDownY3.Text = y.ToString();
            }
        }

        private void checkBox2_CheckedChanged(object sender, EventArgs e)
        {
            if (!tbPointX.Text.Equals("") && !tbPointY.Text.Equals("") && !tbLeftDownCol1.Text.Equals("") && !tbLeftDownRow1.Text.Equals("") && !tbLeftDownCol2.Text.Equals("") && !tbLeftDownRow2.Text.Equals(""))
            {
                int x, y;
                GetPoint9(LeftDownRowCross[0], LeftDownColCross[0], LeftDownRowCross[1], LeftDownColCross[1], LeftDownRowCross[2], LeftDownColCross[2], Convert.ToInt32(tbLeftDownX1.Text), Convert.ToInt32(tbLeftDownY1.Text), Convert.ToInt32(tbLeftDownX2.Text), out x, out y);
                tbLeftDownX3.Text = x.ToString();
                tbLeftDownY3.Text = y.ToString();
            }
        }

        private void panel1_MouseDown(object sender, MouseEventArgs e)
        {
            Tool.FormMove(Handle);
        }


        private void button24_MouseDown(object sender, MouseEventArgs e)
        {
            HTuple hv_RowT = null, hv_ColT = null, hv_PhiT = null, hv_Length1T = null, hv_Length2T = null;
            HTuple hv_RowBeginT = null, hv_ColBeginT = null, hv_RowEndT = null, hv_ColEndT = null;
            HTuple hv_RowBeginT1 = null, hv_ColBeginT1 = null, hv_RowEndT1 = null, hv_ColEndT1 = null;
            HWindow hw = new HWindow(); HObject image = new HObject();
            try
            {
                switch ((sender as Button).Text)
                {
                    case "左上相机比例": hw = hwindow[0]; image = LeftUpImage; break;
                    case "右上相机比例": hw = hwindow[1]; image = RightUpImage; break;
                    case "左下相机比例": hw = hwindow[2]; image = LeftDownImage; break;
                    case "右下相机比例": hw = hwindow[3]; image = RightDownImage; break;
                    default:
                        break;
                }
                double dbCameraBl = 0.0;
                GetParam();
                if (!double.TryParse(tbBD.Text.Trim(), out dbCameraBl))
                {
                    MessageBox.Show(this, "请输入正确的尺寸距离数值！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    tbBD.Focus();
                    return;
                }
                HOperatorSet.DispImage(image, hw);
                hw.SetTposition(50, 50);
                hw.WriteString($"请开始找边");
                HTuple h1 = new HTuple(), h2 = new HTuple(), h3 = new HTuple(), h4 = new HTuple(), hh = new HTuple();
                HOperatorSet.SetDraw(hw, "margin");
                HOperatorSet.SetColor(hw, "green");
                this.Focus();
                HOperatorSet.DrawRectangle2(hw, out hv_RowT, out hv_ColT, out hv_PhiT, out hv_Length1T,
                    out hv_Length2T);
                pLeftUp.Focus();
                //找边算子
                imageprocesses.rake_edge(image, hw, hv_RowT, hv_ColT, hv_PhiT, hv_Length1T, hv_Length2T, hv_Step, 1, hv_Gray,
                    hv_Transition, "first", "TRUE", "TRUE", "TRUE", out hv_RowBeginT, out hv_ColBeginT, out hv_RowEndT, out hv_ColEndT);

                HOperatorSet.DrawRectangle2(hw, out hv_RowT, out hv_ColT, out hv_PhiT, out hv_Length1T,
                    out hv_Length2T);

                //找边算子
                imageprocesses.rake_edge(image, hw, hv_RowT, hv_ColT, hv_PhiT, hv_Length1T, hv_Length2T, hv_Step, 1, hv_Gray,
                    hv_Transition, "first", "TRUE", "TRUE", "TRUE", out hv_RowBeginT1, out hv_ColBeginT1, out hv_RowEndT1, out hv_ColEndT1);
                h1 = (hv_RowBeginT + hv_RowEndT) / 2;
                h2 = (hv_ColEndT + hv_ColBeginT) / 2;
                HOperatorSet.DistancePl(h1, h2, hv_RowBeginT1, hv_ColBeginT1, hv_RowEndT1, hv_ColEndT1, out hh);
                tbBDPixelRatio.Text = double.Parse((dbCameraBl / hh).ToString()).ToString("0.000");
                hw.SetTposition(350, 50);
                hw.WriteString($"像素比列为：{double.Parse((dbCameraBl / hh).ToString()).ToString("0.000")}");

                if (PublicSet.Myset.DetectMode == "2相机正负双测")
                {
                    switch ((sender as Button).Text)
                    {
                        case "左上相机比例": PublicSet.Cameraset.NLeftUpCamreraPixelRatio = double.Parse(double.Parse((dbCameraBl / hh).ToString()).ToString("0.000")); break;
                        case "左下相机比例": PublicSet.Cameraset.NLeftDownCamreraPixelRatio = double.Parse(double.Parse((dbCameraBl / hh).ToString()).ToString("0.000")); break;
                        case "右上相机比例": PublicSet.Cameraset.PRightUpCamreraPixelRatio = double.Parse(double.Parse((dbCameraBl / hh).ToString()).ToString("0.000")); break;
                        case "右下相机比例": PublicSet.Cameraset.PRightDownCamreraPixelRatio = double.Parse(double.Parse((dbCameraBl / hh).ToString()).ToString("0.000")); break;
                        default:
                            break;
                    }
                }
                if (PublicSet.Myset.DetectMode == "3相机正负单测" && NOrP == "N")
                {
                    switch ((sender as Button).Text)
                    {
                        case "左上相机比例": PublicSet.Cameraset.NLeftUpCamreraPixelRatio = double.Parse(double.Parse((dbCameraBl / hh).ToString()).ToString("0.000")); break;
                        case "左下相机比例": PublicSet.Cameraset.NLeftDownCamreraPixelRatio = double.Parse(double.Parse((dbCameraBl / hh).ToString()).ToString("0.000")); break;
                        case "右上相机比例": PublicSet.Cameraset.NRightUpCamreraPixelRatio = double.Parse(double.Parse((dbCameraBl / hh).ToString()).ToString("0.000")); break;
                        default:
                            break;
                    }
                }
                else
                {
                    switch ((sender as Button).Text)
                    {
                        case "左上相机比例": PublicSet.Cameraset.PLeftUpCamreraPixelRatio = double.Parse(double.Parse((dbCameraBl / hh).ToString()).ToString("0.000")); break;
                        case "左下相机比例": PublicSet.Cameraset.PLeftDownCamreraPixelRatio = double.Parse(double.Parse((dbCameraBl / hh).ToString()).ToString("0.000")); break;
                        case "右上相机比例": PublicSet.Cameraset.PRightUpCamreraPixelRatio = double.Parse(double.Parse((dbCameraBl / hh).ToString()).ToString("0.000")); break;
                        default:
                            break;
                    }
                }

                if (PublicSet.Myset.DetectMode == "8相机正负双测" && NOrP == "N")
                {
                    switch ((sender as Button).Text)
                    {
                        case "左上相机比例": PublicSet.Cameraset.NLeftUpCamreraPixelRatio = double.Parse(double.Parse((dbCameraBl / hh).ToString()).ToString("0.000")); break;
                        case "左下相机比例": PublicSet.Cameraset.NLeftDownCamreraPixelRatio = double.Parse(double.Parse((dbCameraBl / hh).ToString()).ToString("0.000")); break;
                        case "右上相机比例": PublicSet.Cameraset.NRightUpCamreraPixelRatio = double.Parse(double.Parse((dbCameraBl / hh).ToString()).ToString("0.000")); break;
                        case "右下相机比例": PublicSet.Cameraset.NRightDownCamreraPixelRatio = double.Parse(double.Parse((dbCameraBl / hh).ToString()).ToString("0.000")); break;
                        default:
                            break;
                    }
                }
                else
                {
                    switch ((sender as Button).Text)
                    {
                        case "左上相机比例": PublicSet.Cameraset.PLeftUpCamreraPixelRatio = double.Parse(double.Parse((dbCameraBl / hh).ToString()).ToString("0.000")); break;
                        case "左下相机比例": PublicSet.Cameraset.PLeftDownCamreraPixelRatio = double.Parse(double.Parse((dbCameraBl / hh).ToString()).ToString("0.000")); break;
                        case "右上相机比例": PublicSet.Cameraset.PRightUpCamreraPixelRatio = double.Parse(double.Parse((dbCameraBl / hh).ToString()).ToString("0.000")); break;
                        case "右下相机比例": PublicSet.Cameraset.PRightDownCamreraPixelRatio = double.Parse(double.Parse((dbCameraBl / hh).ToString()).ToString("0.000")); break;
                        default:
                            break;
                    }
                }


            }
            catch (Exception ex)
            {
                Tool.LogForm("btnCameraBd_Click()->EX:" + ex.ToString());
            }
        }



        /// <summary>
        /// 获取标定找边参数
        /// </summary>
        private void GetParam()
        {
            hv_Step = Convert.ToInt32(nStep.Text.Trim()); ;
            string str = cbMode.Text;
            if (str == "白->黑")
            {
                hv_Transition = "negative";
            }
            else if (str == "黑->白")
            {
                hv_Transition = "positive";
            }
            else
            {
                hv_Transition = "all";
            }
            if (cbSelectPoint.Text == "第一点")
            {
                hv_Select = "first";
            }
            else if (cbSelectPoint.Text == "最后点")
            {
                hv_Select = "last";
            }
            else
            {
                hv_Select = "all";
            }
            hv_Gray = Convert.ToInt32(nGray.Text.Trim()); ;
        }

        /// <summary>
        /// 获取标定的物理坐标
        /// </summary>
        /// <param name="hv_Row">第1个采集点的图像坐标</param>
        /// <param name="hv_Column">第1个采集点的图像坐标</param>
        /// <param name="hv_Row0">第2个采集点的图像坐标</param>
        /// <param name="hv_Column0">第2个采集点的图像坐标</param>
        /// <param name="hv_Row00">第3个采集点的图像坐标</param>
        /// <param name="hv_Column00">第3个采集点的图像坐标</param>
        /// <param name="point_1X">第1个采集点的物理坐标</param>
        /// <param name="point_1y">第1个采集点的物理坐标</param>
        /// <param name="point_2x">第2个采集点的物理坐标</param>
        /// <param name="point_x">得到的物理坐标</param>
        /// <param name="point_y">得到的物理坐标</param>
        private void GetPoint9(HTuple hv_Row, HTuple hv_Column, HTuple hv_Row0, HTuple hv_Column0, HTuple hv_Row00, HTuple hv_Column00, HTuple point_1X, HTuple point_1y, HTuple point_2x, out int point_x, out int point_y)
        {
            HTuple hv_RowProj = new HTuple(), hv_ColProj = new HTuple();
            HTuple hv_juli1 = new HTuple(); HTuple hv_juli10 = new HTuple();
            HTuple hv_y0 = new HTuple(), hv_x0 = new HTuple();
            HTuple hv_WuLi_Y = new HTuple();
            HTuple hv_WuLi_X = new HTuple();
            HTuple hv_BiLie = new HTuple(), hv_Round = new HTuple(), hv_Round1 = new HTuple(); HTuple hv_juli = new HTuple();

            HOperatorSet.DistancePp(hv_Row, hv_Column, hv_Row0, hv_Column0, out hv_juli);
            hv_BiLie = hv_juli / (point_2x - point_1X);
            if (hv_BiLie < 0)
            {
                hv_BiLie = hv_BiLie * -1;
            }

            HOperatorSet.ProjectionPl(hv_Row00, hv_Column00, hv_Row, hv_Column, hv_Row0,
            hv_Column0, out hv_RowProj, out hv_ColProj);

            HOperatorSet.DistancePp(hv_RowProj, hv_ColProj, hv_Row00, hv_Column00, out hv_juli1);
            HOperatorSet.DistancePp(hv_RowProj, hv_ColProj, hv_Row, hv_Column, out hv_juli10);

            hv_x0 = 0;
            hv_y0 = 0;

            if ((int)(new HTuple(hv_Row00.TupleGreater(hv_RowProj))) != 0)
            {
                hv_WuLi_Y = (hv_juli1 / hv_BiLie) * 1;
                //WuLi_X := juli10/BiLie  *1
                if (checkBox2.Checked)
                {
                    hv_WuLi_Y = hv_WuLi_Y * -1;
                }
            }
            if ((int)(new HTuple(hv_Row00.TupleLess(hv_RowProj))) != 0)
            {
                hv_WuLi_Y = (hv_juli1 / hv_BiLie) * -1;
                if (checkBox2.Checked)
                {
                    hv_WuLi_Y = hv_WuLi_Y * -1;
                }
                hv_WuLi_X = (hv_juli10 / hv_BiLie) * -1;
            }

            if ((int)(new HTuple(hv_Column00.TupleGreater(hv_Column))) != 0)
            {
                //WuLi_Y := juli1/BiLie*1
                hv_WuLi_X = (hv_juli10 / hv_BiLie) * 1;
                if (checkBox1.Checked)
                {
                    hv_WuLi_X = hv_WuLi_X * -1;
                }
            }
            if ((int)(new HTuple(hv_Column00.TupleLess(hv_Column))) != 0)
            {
                hv_WuLi_X = (hv_juli1 / hv_BiLie) * -1;
                if (checkBox1.Checked)
                {
                    hv_WuLi_X = hv_WuLi_X * -1;
                }
            }

            HOperatorSet.TupleRound(hv_WuLi_X, out hv_Round);
            HOperatorSet.TupleRound(hv_WuLi_Y, out hv_Round1);
            point_x = hv_Round + (point_1X - (Convert.ToInt32(tbPointX.Text)) + Convert.ToInt32(tbPointX.Text));
            point_y = hv_Round1 + (point_1y - (Convert.ToInt32(tbPointY.Text)) + Convert.ToInt32(tbPointY.Text));

        }


        private List<double> GetInterPoint1(HObject ho_Image, HWindow hwindow, HTuple RowCross, HTuple ColCross)
        {
            HTuple hv_RowT = null, hv_ColT = null, hv_PhiT = null, hv_Length1T = null, row_zhongxing = null, col_zhongxin = null;
            HObject re = new HObject();
            List<double> lb = new List<double>();
            try
            {
                this.Focus();
                HOperatorSet.DispImage(ho_Image, hwindow);
                HOperatorSet.SetColor(hwindow, "green");
                HOperatorSet.SetDraw(hwindow, "margin");
                for (int i = 0; i < 8; ++i)
                {
                    HOperatorSet.DispCross(hwindow, RowCross[i], ColCross[i], 30, 0);
                }
                //MessageBox.Show("请找到横竖两个直线，\n 点击 <<鼠标右键>> 提交找边区域！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                hwindow.SetTposition(10, 10);
                hwindow.WriteString("请画框找《横竖向的边缘》！");
                re.Dispose();
                HOperatorSet.DrawRectangle1(hwindow, out hv_RowT, out hv_ColT, out hv_PhiT, out hv_Length1T);
                HOperatorSet.GenRectangle1(out re, hv_RowT, hv_ColT, hv_PhiT, hv_Length1T);
                HOperatorSet.AreaCenter(re, out _, out row_zhongxing, out col_zhongxin);

                imageprocesses.MeasureLine_Bd(ho_Image, hwindow, hv_RowT, hv_ColT, hv_PhiT, hv_Length1T, row_zhongxing, col_zhongxin, hv_Step, hv_Gray, hv_Transition, hv_Select, out HTuple hv_RowPoint, out HTuple hv_ColPoint);

                hwindow.NewLine();
                hwindow.WriteString("角点 Row:" + hv_RowPoint.D.ToString("0.000") + " Col:" + hv_ColPoint.D.ToString("0.000"));

                lb.Add(hv_RowPoint.D);
                lb.Add(hv_ColPoint.D);
                re.Dispose();
            }
            catch (Exception ex)
            {
                re.Dispose();
                Tool.LogForm("标定找边报错->EX:" + ex.ToString());
            }
            return lb;
        }
    }
}
